import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/hj_page/mine_business/more_question/feedback_question_category_view.dart';
import 'package:tiktokadult/hj_page/mine_business/more_question/mine_feedback_logic.dart';
import 'package:tiktokadult/hj_page/mine_business/more_question/mine_qa_page.dart';
import 'package:tiktokadult/hj_page/mine_business/more_question/photo_manage_view.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

class MineFeedbackPage extends StatelessWidget {
  static const String routeName = '/feedback';
  const MineFeedbackPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MineFeedbackLogic>(
      init: MineFeedbackLogic(),
      builder: (controller) => Scaffold(
        appBar: AppBar(
          title: Text('意见反馈'),
          actions: [
            InkWell(
              onTap: () => Get.to(() => MineQAPage()),
              child: Text(
                'Q&A',
                style: TextStyle(
                  color: Colors.white.withOpacity(0.45),
                  fontSize: 12,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ),
            16.sizeBoxW,
          ],
        ),
        body: Column(
          children: [
            Expanded(
              child: SingleChildScrollView(
                  keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
                  child: Padding(
                    padding: EdgeInsets.only(left: 10, right: 10, top: 12),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '遇到的问题',
                          style: TextStyle(
                            color: Colors.white.withOpacity(0.9),
                            fontSize: 18,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        12.sizeBoxH,
                        FeedbackQuestionCategoryView(
                          choseCategory: controller.updateQuestionCategory,
                        ),
                        24.sizeBoxH,
                        Text(
                          '问题描述(必填)',
                          style: TextStyle(color: Colors.white.withOpacity(0.9), fontSize: 18, fontWeight: FontWeight.w600),
                        ),
                        12.sizeBoxH,
                        Container(
                          constraints: BoxConstraints(minHeight: 160),
                          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
                          decoration: BoxDecoration(
                            color: Colors.white.withOpacity(.05),
                            borderRadius: BorderRadius.circular(8),
                          ),
                          child: Stack(
                            children: [
                              TextField(
                                maxLines: 8,
                                style: TextStyle(color: Colors.white.withOpacity(0.9), fontSize: 12),
                                maxLength: 300,
                                controller: controller.inputFeedback,
                                decoration: InputDecoration(
                                    border: InputBorder.none,
                                    hintText: '请简单描述一下您遇到的问题...',
                                    hintStyle: TextStyle(color: Color(0xff525252), fontSize: 12),
                                    counterStyle: TextStyle(fontSize: 8),
                                    counter: SizedBox(),
                                    contentPadding: EdgeInsets.zero,
                                    isDense: true),
                              ),
                              Positioned(
                                child: ChangeNotifierProvider(
                                  create: (_) => controller.inputFeedback,
                                  child: Consumer<TextEditingController>(
                                    builder: (__, ctr, child) => Text(
                                      '${ctr.text.length}/300',
                                      style: TextStyle(
                                        color: Colors.black.withOpacity(0.5),
                                        fontSize: 12,
                                      ),
                                    ),
                                  ),
                                ),
                                bottom: 0,
                                right: 0,
                              )
                            ],
                          ),
                        ),
                        14.sizeBoxH,
                        InfomationInputView(controller.areaFeedback, title: '所在地区', hint: '例:浙江杭州'),
                        InfomationInputView(controller.deviceFeedback, title: '设备信息', hint: '例:苹果14'),
                        InfomationInputView(controller.netFeedback, title: '网络运营商', hint: '电信/联通/移动'),
                        InfomationInputView(controller.contactFeedback, title: '联系方式', hint: 'QQ/微信/邮箱等'),
                        24.sizeBoxH,
                        Text(
                          '上传图片',
                          style: TextStyle(color: Colors.white.withOpacity(0.9), fontSize: 18, fontWeight: FontWeight.w700),
                        ),
                        12.sizeBoxH,
                        PhotoManageView(
                          resourceOnchanged: controller.updateQuestionImages,
                        ),
                        24.sizeBoxH,
                        Text(
                          '以方便我们给您回复,有效的改进建议,有惊喜赠送哟!',
                          style: TextStyle(color: Color(0xff525252), fontSize: 12),
                        ),
                        60.sizeBoxH,
                      ],
                    ),
                  )),
            ),
            GestureDetector(
              onTap: controller.onSubmit,
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 45),
                alignment: Alignment.center,
                height: 44,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(3),
                  color: AppColors.actionRed,
                ),
                child: Text(
                  '提交意见',
                  style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w600),
                ),
              ),
            ),
            20.sizeBoxH,
          ],
        ),
      ),
    );
  }
}
